package basicType;

/**
 * 深浅拷贝测试
 * @author chenxin
 * @time 2017-04-22-14:21
 */
public class CloneTest {
    public static void main(String[] args) throws Exception{
        MyObject a = new MyObject();
        a.setStr("123");
        a.setFoo(1);

        MyObject b =  a.clone();
        System.out.println(b.getStr() == a.getStr());

        a.setStr("456");

        System.out.println(b.getStr() == a.getStr());
        System.out.println(b.getStr());

    }

    private static class MyObject implements Cloneable{
        private String str;

        private int foo;

        public int getFoo() {
            return foo;
        }

        public void setFoo(int foo) {
            this.foo = foo;
        }

        public String getStr() {
            return str;
        }

        public void setStr(String str) {
            this.str = str;
        }

        @Override
        public MyObject clone() throws CloneNotSupportedException{
            MyObject target =  (MyObject) super.clone();

            return target;
        }
    }

}
